package Entity;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

import Control.MySQLController;

public class NeedyResident_CreateAccount extends User{
	
	public NeedyResident_CreateAccount(String nric, String name,
			String email, int contact_no, Date dob,
			String address, char gender, String user_status_code,
			String password) {
		super(nric, name, email, contact_no, dob, address, gender,
				user_status_code, password);
		// TODO Auto-generated constructor stub
	}

	public NeedyResident_CreateAccount() {
		// TODO Auto-generated constructor stub
	}

	private double monthlySalary;
	private String location;
	private String postalCode;
	private int familySize;
	private String race;
	
	
	
	public double getMonthlySalary() {
		return monthlySalary;
	}
	public void setMonthlySalary(double monthlySalary) {
		this.monthlySalary = monthlySalary;
	}
	public String getLocation() {
		return location;
	}
	public void setLocation(String location) {
		this.location = location;
	}
	public String getPostalCode() {
		return postalCode;
	}
	public void setPostalCode(String postalCode) {
		this.postalCode = postalCode;
	}
	public int getFamilySize() {
		return familySize;
	}
	public void setFamilySize(int familySize) {
		this.familySize = familySize;
	}
	public String getRace() {
		return race;
	}
	public void setRace(String race) {
		this.race = race;
	}
	
	public boolean createNeedyResident(){
		boolean success = false;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		setUser_status_code("A");
		MySQLController db = new MySQLController();
		db.getConnection();
		//input into User database
		String sql = "INSERT INTO ooadpj.user(nric, username, password, name, email, contact_no, dob, address, gender, user_status_code )";
		sql += "VALUES ('" + getNric() + "', '"+getNric() +"','" +  getPassword() + "','" + getName() + "','" + getEmail() + "',"+ getContact_no() + ",'" + sdf.format(getDob()) + "','" + getAddress() +"','"+ getGender() +"','" + getUser_status_code() + "')";
		//input into Needy resident database
		String sql2 = "INSERT INTO ooadpj.needy_resident(nric, monthly_income, family_size )";
		sql2 += "VALUES ('" + getNric() + "','" + getMonthlySalary() + "','" + getFamilySize() + "')";
		if(db.updateRequest(sql)==1 && db.updateRequest(sql2)==1)
			success = true;
		db.terminate();
		return success;
	}
	

}
